
package com.plian.system.service.fr.financeindicators.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.plian.Tools.CollectionUtil;
import com.plian.system.entity.fr.indicators.FinanceIndicatorsSupplement;
import com.plian.system.mapper.fr.indicators.FinanceIndicatorsSupplementMapper;
import com.plian.system.service.fr.financeindicators.IFinanceIndicatorsSupplementService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 指标定义补充表 服务实现类
 *
 * @author jianglei
 * @since 2019-10-23
 */
@Service
@AllArgsConstructor
public class FinanceIndicatorsSupplementServiceImpl extends ServiceImpl<FinanceIndicatorsSupplementMapper, FinanceIndicatorsSupplement> implements IFinanceIndicatorsSupplementService {
    /**
     * logger属性.
     */
    private static final Logger LOGGER  = LoggerFactory.getLogger(FinanceIndicatorsSupplementServiceImpl.class);

    @Override
    public void init(int year) {
        List<FinanceIndicatorsSupplement> oldList = list(new LambdaQueryWrapper<FinanceIndicatorsSupplement>().eq(FinanceIndicatorsSupplement::getYear, year - 1));
        if (CollectionUtil.isEmpty(oldList)){
            return;
        }
        for (FinanceIndicatorsSupplement financeIndicatorsSupplement : oldList){
            financeIndicatorsSupplement.setId(null);
            financeIndicatorsSupplement.setYear(String.valueOf(year));
        }
        remove(new LambdaQueryWrapper<FinanceIndicatorsSupplement>().eq(FinanceIndicatorsSupplement::getYear, year));
        saveBatch(oldList);
    }
}
